package com.lzcu.maoyan.maoyanweb.control;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.lzcu.maoyan.maoyanweb.pojo.MovieBoxOfficePojo;
import com.lzcu.maoyan.maoyanweb.service.MovieEcharts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author WangLiang
 * @date `2024/4/22`
 */
@Controller
@RequestMapping
public class BoxOfficeControl {

    @Autowired
    MovieEcharts movieEcharts;

    @GetMapping("/queryMaxTotal20")
    @ResponseBody
    public String getMaxTotalSessions() {
        List<Map<String, Object>> result = movieEcharts.queryMaxTotalSessions();
        return JSONObject.toJSONString(result);
    }

    @GetMapping("/queryMovieCount")
    @ResponseBody
    public String getMovieCount() {
        return JSONObject.toJSONString(movieEcharts.queryMovieCount());
    }

    @GetMapping("/queryMovieTypeCount")
    @ResponseBody
    public String getMovieTypeCount() {
        return JSONObject.toJSONString(movieEcharts.queryMovieTypeCount());
    }

    @GetMapping("/dailyMovieDetails")
    @ResponseBody
    public String getDailyMovieDetails() {
        List<MovieBoxOfficePojo> movieBoxOfficePojos = movieEcharts.queryDailyMovieDetails();
        JSONArray result = JSONArray.parseArray(JSONObject.toJSONString(movieBoxOfficePojos));
        for (Object item : result) {
            String timeInfo = (String) ((JSONObject) item).get("mOVIE_TIME_INFO");
            ((JSONObject) item).put("mOVIE_TIME_INFO", timeInfo.replace(".000", ""));
        }
        return result.toJSONString();
    }

    @GetMapping("/movieLeadingActor")
    @ResponseBody
    public String getMovieLeadingActor(){
        return JSONObject.toJSONString(movieEcharts.queryMovieLeadingActor());
    }

    @GetMapping("/springFestivalTop")
    @ResponseBody
    public String getSpringFestivalTop(){
        return JSONObject.toJSONString(movieEcharts.querySpringFestivalTop());
    }

    @GetMapping("/springFestival")
    @ResponseBody
    public String getSpringFestival(){
        return JSONObject.toJSONString(movieEcharts.querySpringFestival());
    }
    @GetMapping("/movieTypeTotal")
    @ResponseBody
    public String getMovieTypeTotal(){
        return JSONObject.toJSONString(movieEcharts.queryMovieTypeTotal());
    }
}
